﻿using UnityEngine;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Collections;


public class UserSettings : MonoBehaviour
{

    // Use this for initialization
    void Start()
    {



    }

    // Update is called once per frame
    void Update()
    {


    }

    public void saveSettings()
    {
        //List<string> stringSettings = new List<string>();
        //stringSettings.Add(Screen.currentResolution.width.ToString());
        //stringSettings.Add(Screen.currentResolution.height.ToString());
        //stringSettings.Add(QualitySettings.antiAliasing.ToString());

        string[] settingsArray = new string[] { Screen.currentResolution.width.ToString(), Screen.currentResolution.height.ToString(), QualitySettings.antiAliasing.ToString(),
            QualitySettings.vSyncCount.ToString(), AudioListener.volume.ToString() };

        using (StreamWriter sw = new StreamWriter("userSettings.txt"))
        {
            foreach (string item in settingsArray)
            {
                sw.WriteLine(item);
            }
        }
    }

    // public string[] saveKeybindings()

    public void loadSettings()
    {
        using (StreamReader sr = new StreamReader("userSettings.txt"))
        {
            string input = sr.ReadToEnd();
            string[] settingsArray = input.Split('\n');

            Screen.SetResolution(int.Parse(settingsArray[0]), int.Parse(settingsArray[1]), true);
            QualitySettings.antiAliasing = int.Parse(settingsArray[2]);
            QualitySettings.vSyncCount = int.Parse(settingsArray[3]);
            AudioListener.volume = float.Parse(settingsArray[4]);

            //Debug.Log(settingsArray[3]);
        }
    }

    public string[] loadKeybindings()
    {
        List<string> keys = new List<string>();

        using (StreamReader sr = new StreamReader("userSettings.txt"))
        {
            string input = sr.ReadToEnd();
            string[] settingsArray = input.Split('\n');

            for (int i = 5; i < settingsArray.Length - 5; i++)
                keys.Add(settingsArray[i]);
        }

        return keys.ToArray();
    }
}
